#include "chatuserwid.h"
#include "ui_chatuserwid.h"
#include <QTime>

ChatUserWid::ChatUserWid(QWidget *parent) :
    ListItemBase(parent),
    ui(new Ui::ChatUserWid)
{
    ui->setupUi(this);
    SetItemType(ListItemType::CHAT_USER_ITEM);
}
ChatUserWid::~ChatUserWid()
{
    delete ui;
}
void ChatUserWid::SetInfo(QString name, QString head, QString msg)
{
    qDebug()<<"name:"<<name<<" head:"<<head<<" msg:"<<msg;
    _name = name;
    _head = head;
    _msg = msg;
    // 加载图片
    QPixmap pixmap(_head);
    // 设置图片自动缩放
    ui->icon_label->setPixmap(pixmap.scaled(ui->icon_label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
    ui->icon_label->setScaledContents(true);
    ui->user_name_label->setText(_name);
    ui->user_chat_label->setText(_msg);
    /*
     * 加载时间
    */
    ui->time_label->setText("13:44");
}

void ChatUserWid::SetInfo(std::shared_ptr<UserInfo> user_info)
{
    _user_info = user_info;
//   // 加载图片
//   QPixmap pixmap(_user_info->_icon);

//   // 设置图片自动缩放
//   ui->icon_label->setPixmap(pixmap.scaled(ui->icon_label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
//   ui->icon_label->setScaledContents(true);
//   ui->user_name_label->setText(_user_info->_name);
//   ui->user_name_label->setText(_user_info->_last_msg);
//   ui->time_label->setText("13:44");
    _name = user_info->_name;
    _head = user_info->_icon;
    _msg = user_info->_last_msg;
    // 加载图片
    QPixmap pixmap(_head);
    // 设置图片自动缩放
    ui->icon_label->setPixmap(pixmap.scaled(ui->icon_label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
    ui->icon_label->setScaledContents(true);
    ui->user_name_label->setText(_name);
    ui->user_chat_label->setText(_msg);
    /*
     * 加载时间
    */
    ui->time_label->setText("13:44");
}

std::shared_ptr<UserInfo> ChatUserWid::GetUserInfo()
{
    return _user_info;
}

void ChatUserWid::updateLastMsg(QVector<std::shared_ptr<TextChatData> > msgdata)
{

}

